package com.listtest;


import java.util.ArrayList;
import java.util.List;

public class ListTest {
    public static void main(String[] args) {
        List list = new ArrayList();
        list.add(0,1);
        System.out.println(list);
        list.add(0,2);
        System.out.println(list);
        list.add(0,3);
        System.out.println(list);
        System.out.println(list.addAll(0,list));
        System.out.println(list);
        list.addAll(1,list);
        System.out.println(list);
        list.remove(2);
        System.out.println(list);
        list.remove(3);
        System.out.println(list);
        //返回集合中需要被替换的元素
        System.out.println(list.set(0,324234234));
        System.out.println(list);
        //查找指定位置的元素(注意下标越界)
        System.out.println(list.get(0));
        //System.out.println(list.get(111)); 下标越界 报错
        System.out.println(list.indexOf(1));
        System.out.println(list.indexOf(33243243));
        System.out.println(list.lastIndexOf(1));
        System.out.println();
        System.out.println(list);
        //集合名.subList([起始下标,结束下标)) 作用：返回一个List集合的其中一部分视图。
        System.out.println(list.subList(0,5));
        System.out.println(list);
    }
}
